package com.gxa.service.shezhiservice.Impl;

import com.gxa.common.R;
import com.gxa.mapper.shezhimapper.ZhiChuType46Mapper;
import com.gxa.pojo.ZhiChuType;
import com.gxa.service.shezhiservice.ZhiChuType46Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class ZhiChuType46ServiceImpl implements ZhiChuType46Service {

    @Autowired
    private ZhiChuType46Mapper zhiChuType46Mapper;
    @Override
    public R selectAllZhiChuTypeForPage(int page, int size) {
        R r = new R();
        int index = (page - 1)*size;
        List<ZhiChuType> zhiChuTypes = zhiChuType46Mapper.selectAllZhiChuTypeForPage(index,size);
        if (zhiChuTypes != null){
            r.setCode(200);
            r.setMsg("查询成功！");
            r.setData(zhiChuTypes);
        }
        return r;
    }

    @Override
    public R selectZhiChuTypeByType(int page, int size, String zhiChuType) {
        R r = new R();
        int index = (page - 1)*size;
        List<ZhiChuType> zhiChuTypes = zhiChuType46Mapper.selectZhiChuTypeByType(index,size,zhiChuType);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(zhiChuTypes);
        return r;
    }

    @Override
    public R insertZhiChuType(ZhiChuType zhiChu) {
        R r = new R();
        int res =  zhiChuType46Mapper.insertZhiChuType(zhiChu);
        r.setCode(500);
        r.setMsg("新增失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    @Override
    public R updateZhiChuTypeById(ZhiChuType zhiChu) {
        R r = new R();
        int res =  zhiChuType46Mapper.updateZhiChuTypeById(zhiChu);
        r.setCode(500);
        r.setMsg("更新失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("更新成功");
        }
        return r;
    }

    @Override
    public R deleteZhiChuTypeById(int id) {
        R r = new R();
        int res = zhiChuType46Mapper.deleteZhiChuTypeById(id);
        r.setCode(500);
        r.setMsg("删除失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }

}
